package com.ww.java8.fp.stream.parallel;

import java.util.ArrayList;
import java.util.List;

public class PerformanceComparisonDemo {

    public static void main(String[] args) {
        test01();
    }

    static void test01() {
        long currentTime = System.currentTimeMillis();
        List<Integer> data = new ArrayList<>();
        for (int i = 0; i < 100000; i++) {
            data.add(i);
        }

        long sum = data.stream()
                .map(i -> (int) Math.sqrt(i))
                .map(number -> performComputation(number))
                .reduce(0, Integer::sum);
        System.out.println(sum);
        long endTime = System.currentTimeMillis();
        System.out.println("耗时" + (endTime - currentTime) / (1000) + "秒");
    }

    static int performComputation(int number) {
        int sum = 0;
        for (int i = 1; i < 1000000; i++) {
            int div = (number / i);
            sum += div;
        }
        return sum;
    }
}
